import os
from config import Config

def init():  # 初始化
    global _global_dict
    _global_dict = {}

    _global_dict['model_root'] = os.environ.get("MACA_CONVERTER_MODEL_ROOT")
    _global_dict['maca_converter_root'] = os.environ.get("MACA_CONVERTER_TOOL_ROOT")

    #file_path = os.path.join(path, file)

    _global_dict['maca_converter_path'] = Config["maca_converter_path"]

    _global_dict['caffe_model_path'] = Config["model_path"]["caffe2onnx"]["model"]
    _global_dict['caffe_input_npy'] = Config["model_path"]["caffe2onnx"]["input"]
    _global_dict['caffe_output_npy'] = Config["model_path"]["caffe2onnx"]["output"]

    _global_dict['h5_model_path'] = Config["model_path"]["h52onnx"]["model"]
    _global_dict['h5_inputs_as_nchw'] = Config["model_path"]["h52onnx"]["inputs_as_nchw"]
    _global_dict['h5_input_npy'] = Config["model_path"]["h52onnx"]["input"]
    _global_dict['h5_output_npy'] = Config["model_path"]["h52onnx"]["output"]

    _global_dict['sm_model_path'] = Config["model_path"]["sm2onnx"]["model"]
    _global_dict['sm_input_npy'] = Config["model_path"]["sm2onnx"]["input"]
    _global_dict['sm_output_npy'] = Config["model_path"]["sm2onnx"]["output"]

    _global_dict['ckpt_model_path'] = Config["model_path"]["ckpt2onnx"]["model"]
    _global_dict['ckpt_model_inputs'] = Config["model_path"]["ckpt2onnx"]["inputs"]
    _global_dict['ckpt_model_outputs'] = Config["model_path"]["ckpt2onnx"]["outputs"]
    _global_dict['ckpt_inputs_as_nchw'] = Config["model_path"]["ckpt2onnx"]["inputs_as_nchw"]
    _global_dict['ckpt_input_npy'] = Config["model_path"]["ckpt2onnx"]["input"]
    _global_dict['ckpt_output_npy'] = Config["model_path"]["ckpt2onnx"]["output"]

    _global_dict['pb_model_path'] = Config["model_path"]["pb2onnx"]["model"]
    _global_dict['pb_model_inputs'] = Config["model_path"]["pb2onnx"]["inputs"]
    _global_dict['pb_model_outputs'] = Config["model_path"]["pb2onnx"]["outputs"]
    _global_dict['pb_inputs_as_nchw'] = Config["model_path"]["pb2onnx"]["inputs_as_nchw"]
    _global_dict['pb_input_npy'] = Config["model_path"]["pb2onnx"]["input"]
    _global_dict['pb_output_npy'] = Config["model_path"]["pb2onnx"]["output"]

    _global_dict['darknet_model_path'] = Config["model_path"]["darknet2onnx"]["model"]
    _global_dict['darknet_input_npy'] = Config["model_path"]["darknet2onnx"]["input"]
    _global_dict['darknet_output_npy'] = Config["model_path"]["darknet2onnx"]["output"]

    _global_dict['subgraph_model_path'] = Config["model_path"]["subgraph"]["model"]
    _global_dict['subgraph_model_inputs'] = Config["model_path"]["subgraph"]["inputs"]
    _global_dict['subgraph_model_outputs'] = Config["model_path"]["subgraph"]["outputs"]

    _global_dict['pytorch2onnx_static_model_path'] = Config["model_path"]["pytorch2onnx_static"]["model"]
    _global_dict['pytorch2onnx_static_model_def_file'] = Config["model_path"]["pytorch2onnx_static"]["model_def_file"]
    _global_dict['pytorch2onnx_static_model_class_name'] = Config["model_path"]["pytorch2onnx_static"]["class"]
    _global_dict['pytorch2onnx_static_model_input_shape'] = Config["model_path"]["pytorch2onnx_static"]["input_shape"]
    _global_dict['pytorch2onnx_static_model_input_npy'] = Config["model_path"]["pytorch2onnx_static"]["input"]
    _global_dict['pytorch2onnx_static_model_output_npy'] = Config["model_path"]["pytorch2onnx_static"]["output"]

    _global_dict['pytorch2onnx_dynamic_model_path'] = Config["model_path"]["pytorch2onnx_dynamic"]["model"]
    _global_dict['pytorch2onnx_dynamic_model_def_file'] = Config["model_path"]["pytorch2onnx_dynamic"]["model_def_file"]
    _global_dict['pytorch2onnx_dynamic_model_class_name'] = Config["model_path"]["pytorch2onnx_dynamic"]["class"]
    _global_dict['pytorch2onnx_dynamic_model_input_shape'] = Config["model_path"]["pytorch2onnx_dynamic"]["input_shape"]
    _global_dict['pytorch2onnx_dynamic_model_weights_file'] = Config["model_path"]["pytorch2onnx_dynamic"]["weights_file"]
    _global_dict['pytorch2onnx_dynamic_model_input_npy'] = Config["model_path"]["pytorch2onnx_dynamic"]["input"]
    _global_dict['pytorch2onnx_dynamic_model_output_npy'] = Config["model_path"]["pytorch2onnx_dynamic"]["output"]

    _global_dict['pytorch2onnx_dynamic_model_path2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["model"]
    _global_dict['pytorch2onnx_dynamic_model_class_name2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["class"]
    _global_dict['pytorch2onnx_dynamic_model_input_shape2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["input_shape"]
    _global_dict['pytorch2onnx_dynamic_model_weights_file2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["weights_file"]
    _global_dict['pytorch2onnx_dynamic_model_input_npy2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["input"]
    _global_dict['pytorch2onnx_dynamic_model_output_npy2'] = Config["model_path"]["pytorch2onnx_dynamic2"]["output"]

    _global_dict['paddle2onnx_static_model_path'] = Config["model_path"]["paddle2onnx_static"]["model"]
    _global_dict['paddle2onnx_static_model_input_npy'] = Config["model_path"]["paddle2onnx_static"]["input"]
    _global_dict['paddle2onnx_static_model_output_npy'] = Config["model_path"]["paddle2onnx_static"]["output"]


    _global_dict['paddle2onnx_dynamic_model_path'] = Config["model_path"]["paddle2onnx_dynamic"]["model"]
    _global_dict['paddle2onnx_dynamic_model_def_file'] = Config["model_path"]["paddle2onnx_dynamic"]["model_def_file"]
    _global_dict['paddle2onnx_dynamic_model_class_name'] = Config["model_path"]["paddle2onnx_dynamic"]["class"]
    _global_dict['paddle2onnx_dynamic_model_input_shape'] = Config["model_path"]["paddle2onnx_dynamic"]["input_shape"]
    _global_dict['paddle2onnx_dynamic_model_weights_file'] = Config["model_path"]["paddle2onnx_dynamic"]["weights_file"]
    _global_dict['paddle2onnx_dynamic_model_input_npy'] = Config["model_path"]["paddle2onnx_dynamic"]["input"]
    _global_dict['paddle2onnx_dynamic_model_output_npy'] = Config["model_path"]["paddle2onnx_dynamic"]["output"]

    _global_dict['paddle2onnx_dynamic_model_path2'] = Config["model_path"]["paddle2onnx_dynamic2"]["model"]
    _global_dict['paddle2onnx_dynamic_model_class_name2'] = Config["model_path"]["paddle2onnx_dynamic2"]["class"]
    _global_dict['paddle2onnx_dynamic_model_input_shape2'] = Config["model_path"]["paddle2onnx_dynamic2"]["input_shape"]
    _global_dict['paddle2onnx_dynamic_model_weights_file2'] = Config["model_path"]["paddle2onnx_dynamic2"]["weights_file"]
    _global_dict['paddle2onnx_dynamic_model_input_npy2'] = Config["model_path"]["paddle2onnx_dynamic2"]["input"]
    _global_dict['paddle2onnx_dynamic_model_output_npy2'] = Config["model_path"]["paddle2onnx_dynamic2"]["output"]

    _global_dict['dynamic_batch_model_path'] = Config["model_path"]["dynamic_batch"]
    _global_dict['fuse_pad2pool_model_path'] = Config["model_path"]["fuse_pad2pool"]
    _global_dict['opset_model_path'] = Config["model_path"]["opset"]
    _global_dict['gap_model_path'] = Config["model_path"]["gap2ap"]
    _global_dict['fp32_to_fp16_model_path'] = Config["model_path"]["fp32_to_fp16"]
    _global_dict['simplify_model_path'] = Config["model_path"]["simplify"]
    _global_dict['mish_model_path'] = Config["model_path"]["mish"]

    _global_dict['preproc_model_path'] = Config["model_path"]["preproc"]["model"]
    _global_dict['preproc_yaml_path'] = Config["model_path"]["preproc"]["yaml"]

    _global_dict['postproc_model_path'] = Config["model_path"]["postproc"]["model"]
    _global_dict['postproc_yaml_path'] = Config["model_path"]["postproc"]["yaml"]

    _global_dict['bn2conv_model_path'] = Config["model_path"]["bn2conv"]
    _global_dict['expand2Resize_model_path'] = Config["model_path"]["expand_to_resize"]
    _global_dict['gemm_model_path'] = Config["model_path"]["gemm_convert"]

def get_value(key):
    try:
        return _global_dict[key]
    except:
        print('read' + key + 'failed\n')
